package com.eshin.demo.custom;

import org.apache.commons.lang3.StringUtils;

import ch.qos.logback.classic.PatternLayout;

public class CustomPatternLayout extends PatternLayout {

	private String keywordPattern;
	
	public String getKeywordPattern() {
		return keywordPattern;
	}
	public void setKeywordPattern(String keywordPattern) {
		this.keywordPattern = keywordPattern;
	}
	static {
		defaultConverterMap.put("TEST", CustomConverter.class.getName());
		CustomConverter.keywordsMap.put("TEST", "test");
	}
	
	public CustomPatternLayout() {
	}
	private void init() {
//		KEYWORDS_PATTERN
//		String keywordPattern = getContext().getProperty("KEYWORDS_PATTERN");
		String[] keywords = StringUtils.split(keywordPattern, ",");
		for(String keyword : keywords) {
			String[] keyword_value = StringUtils.split(keyword, ":");
			CustomConverter.keywordsMap.put(keyword_value[0], keyword_value[1]);
			defaultConverterMap.put(keyword_value[0], CustomConverter.class.getName());
		}
	}
	@Override
	public void start() {
		init();
		super.start();
	}
}
